<template>
	<view class="wrap" :style="colorStyle">
		<!-- <view class="nav_box" :style="{height:navigatorHeight+'px'}">
			<view class="sys_bar" :style="{height:statusBarHeight+'px'}"></view>
			<view class="nav_info">
				<view class="back_icon">
					<view class="iconfont icon-fanhui2"></view>
				</view>
				<view class="sys_title">{{navTitle}}</view>
				<view class="back_icon"></view>
			</view>
		</view> -->
		<view class="list-box" v-if="list.length">
			<block v-for="(item,index) in list" :key="index">
				<view class="list">
					<view class="choos_icon" @click="choosAddrss(item)">
						选择
					</view>
					<view>
						<view class="name flex_s">
							{{item.bank_name||''}}
							<text>{{item.card_username||''}}</text>
							<!-- <view class="tip_box" v-if="item.exceed">
								未在配送范围
							</view> -->
						</view>
						<view class="span">
							<text>{{item.card_number||''}}</text>
						</view>
					</view>

					<view class="btn-box flex_sb">
						<view class="left" @click="set_default(item.id)">
							<view class="img_box">
								<image src="../static/imgs/a2.png" v-if="item.is_default"></image>
								<image src="../static/imgs/a1.png" v-else></image>
							</view>
							设为默认
						</view>
						<view class="right">
							<view class="li" @click="$util.goPage(`/pages/new_page/bank/info?id=${item.id}`)">
								<image src="../static/imgs/my-17.png"></image>
								编辑
							</view>
							<view class="li" @click="openModal(item.id)">
								<image src="../static/imgs/my-18.png"></image>
								删除
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<emptyPage v-else></emptyPage>
		<view class="btn-d">
			<view class="btn" @click="$util.goPage('/pages/new_page/bank/info?playType=1')">添加银行卡</view>
		</view>
		<modal ref="modal" content="是否确认删除?" confirmText="确定" @confirm="del"></modal>
	</view>
</template>
<script>
	import colors from "@/mixins/color";
	import {
		debounceImmediate
	} from "@/utils/validate";
	import emptyPage from "@/components/emptyPage.vue";
	import modal from "@/components/modal/modal.vue";
	import {
		card_list,
		default_set,
		card_del
	} from "@/api/new_api.js";
	import {
		mapGetters
	} from "vuex";
	export default {
		components: {
			emptyPage,
			modal
		},
		mixins: [colors],
		data() {
			return {
				alterMain: false,
				list: [],
				delCode: '',
				chooseAdd: false,
				navigatorHeight: '',
				statusBarHeight: '',
				navTitle:'银行卡管理',
				playType:1 // 银行卡/支付宝
			};
		},
		async onLoad(option) {
			this.getSystemInfo()
			// const that = this;
			if (option.chooseAdd) {
				this.chooseAdd = true
				this.navTitle="选择银行卡"
				uni.setNavigationBarTitle({
					title:"选择银行卡"
				})
			}

		},
		onShow() {
			this.card_list()
		},
		methods: {
			getSystemInfo() {
			
				uni.getSystemInfo({
					success: res => {
						const system = res
						this.statusBarHeight = system.statusBarHeight //状态栏高度
						//获取胶囊信息
						const menu = uni.getMenuButtonBoundingClientRect()
						// this.searchLeft = this.menu.left //搜索按钮的右偏移量
						//导航栏高度= （胶囊顶部距离-状态栏高度） x 2 + 胶囊的高度
						this.navigatorHeight = (menu.top - system.statusBarHeight) * 2 + menu.height + system
							.statusBarHeight
			
			
					}
				})
			},
			choosAddrss(item) {
				if (this.chooseAdd) {
					uni.$emit('choosAddrss', item)
					uni.navigateBack()
				}

			},
			card_list() {
				card_list().then((res) => {
					this.list = res.data
				})
			},
			openModal(id) {
				this.delCode = id
				this.$refs.modal.open()
			},
			del: debounceImmediate(function() {
				let that = this
				card_del({
					id: this.delCode
				}).then((res) => {
					uni.showToast({
						title: res.msg,
						icon: "none",
						success() {
							that.$refs.modal.close()
							that.card_list()
						}
					});
				}).catch((err) => {
					uni.$u.toast(err)
				})
			}),
			set_default(id) {
				let that = this
				const params = {
					id: id
				}
				default_set(params).then((res) => {
					uni.showToast({
						title: res.msg,
						icon: "none",
						success() {
							that.card_list()
						}
					});
				})
			}

		},
	};
</script>
<style lang="scss" scoped>
	.wrap {
		overflow: hidden;
		width: 750rpx;
		min-height: 100vh;
		position: relative;
		background-color: #F6F7FB;
		padding-bottom: 200rpx;

		.nav_box {

			background: #fff;

			.nav_info {
				font-size: 30rpx;
				height: 88rpx;
				flex-grow: 1;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 27rpx;

				.back_icon {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 32rpx;
					height: 32rpx;

					.iconfont {
						font-size: 26rpx;
					}
				}

				.sys_title {
					color:#383838;
					text-align: center;
				}
			}

		}

		.list-box {
			width: 700rpx;
			overflow: hidden;
			margin: 0 auto;

			.list {
				position: relative;
				width: 100%;
				background: white;
				border-radius: 8rpx;
				padding: 20rpx 30rpx;
				position: relative;
				margin-top: 20rpx;
				overflow: hidden;
				line-height: 50rpx;
				color: #3D3D3D;
				font-size: 28rpx;

				.choos_icon {
					position: absolute;
					font-size: 26rpx;
					right: 30rpx;
					top: 20rpx;
					width: 95rpx;
					height: 44rpx;
					border-radius: 44rpx;
					line-height: 44rpx;
					background: #383838;
					color: #fff;
					text-align: center;
				}

				.name {
					font-weight: 700;

					text {
						margin-left: 20rpx;
					}

					.tip_box {
						margin-left: 20rpx;
						font-size: 26rpx;
						color: #808080;
						width: 177rpx;
						text-align: center;
						border-radius: 4rpx;
						background: #EDEDED;
						height: 37rpx;
						line-height: 37rpx;
					}
				}

				.span {
					color: #757575;
					font-size: 26rpx;

					text {
						color: #3D3D3D;
						margin-right: 20rpx;
					}
				}

				.btn-box {
					border-top: solid 1rpx #F3F4F8;
					padding: 10rpx 0 0 0;
					overflow: hidden;
					width: 100%;
					margin-top: 10rpx;

					.left {
						display: flex;
						align-items: center;
						width: 40%;

						vertical-align: top;

						.img_box {
							width: 34rpx;
							height: 34rpx;
							margin-right: 10rpx;

							image {
								width: 100%;
								height: 100%;

							}
						}

					}

					.right {
						display: flex;

						vertical-align: top;

						.li {
							display: flex;
							align-items: center;
							vertical-align: top;
							margin-left: 20rpx;

							image {
								width: 34rpx;
								height: 34rpx;
								display: inline-block;
								vertical-align: top;
								margin-right: 10rpx;
							}
						}
					}
				}
			}
		}

		.btn-d {
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			background-color: white;
			padding: 30rpx;
			font-size: 32rpx;
			color: white;
			text-align: center;
			line-height: 90rpx;
			padding-bottom: 50rpx;

			.btn {
				border-radius: 50rpx;
				background: var(--view-theme);
			}
		}
	}
</style>